package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.TableNumberService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.TableNumberAddVO;
import com.junzhiit.nengji.cms.web.vo.TableNumberBatchAddVO;
import com.junzhiit.nengji.cms.web.vo.TableNumberEditVO;
import com.junzhiit.nengji.cms.web.vo.TableNumberVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("table/number")
public class TableNumberController extends BaseController{
	
	@Autowired
	private TableNumberService tableNumberService;
	
	@ApiOperation("查询所有")
	@RequestMapping(method=RequestMethod.GET)
	public Map<String, Object> findPageAll(DataTablesParamVO dtp,TableNumberVO tableNumberVO) {
		return tableNumberService.findPageAll(dtp,tableNumberVO);
	}
	
	@ApiOperation("添加")
	@RequestMapping(method=RequestMethod.POST)
	public ResultVO add(TableNumberAddVO tableNumberAddVO){
		AssertUtil.notNull(tableNumberAddVO.getCode(), "tableCoset is required");
		AssertUtil.notBlank(tableNumberAddVO.getTableTypeId(), "tableTypeId is required");
		return tableNumberService.add(tableNumberAddVO);
	}
	
	@ApiOperation("批量添加")
	@RequestMapping(value="/batch",method=RequestMethod.POST)
	public ResultVO batchAdd(TableNumberBatchAddVO tableNumberBatchAddVO){
		AssertUtil.notNull(tableNumberBatchAddVO.getStart(), "start is required");
		AssertUtil.notNull(tableNumberBatchAddVO.getEnd(), "end is required");
		AssertUtil.notBlank(tableNumberBatchAddVO.getTableTypeId(), "tableTypeId is required");
		return tableNumberService.batchAdd(tableNumberBatchAddVO);
	}
	
	@ApiOperation("修改")
	@RequestMapping(method=RequestMethod.PUT)
	public ResultVO edit(TableNumberEditVO tableNumberEditVO){
		AssertUtil.notNull(tableNumberEditVO.getCost(), "tableCoset is required");
		return tableNumberService.edit(tableNumberEditVO);
	}
	
	@ApiOperation("重新生成")
	@RequestMapping(value="/regenerate",method=RequestMethod.PUT)
	public ResultVO regenerate(String id){
		AssertUtil.notBlank(id, "id is required");
		return tableNumberService.regenerate(id);
	}
	
	@ApiOperation("更新删除")
	@RequestMapping(value="/delete/{id}",method=RequestMethod.PUT)
	public ResultVO updateToDelete(@PathVariable String id){
		AssertUtil.notBlank(id, "id is required");
		return tableNumberService.updateToDelete(id);
	}
	
	
}
